<template>
  <!--  检索结果表格-->
  <div style="padding-top: 20px;width: 100%;height: 100%">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column fixed prop="id" label="id" width="50"/>
      <el-table-column fixed prop="userId" label="用户Id" width="120"/>
      <el-table-column prop="email" label="用户邮箱" width="150" />
      <el-table-column prop="mobilePhoneNumber" label="手机号" width="100" />
      <el-table-column prop="nickname" label="昵称" width="100" />
      <el-table-column prop="ip" label="联系地址" width="200" />
      <el-table-column prop="school" label="学校" width="200" />
      <el-table-column prop="major" label="专业" width="200" />
      <!--      <el-table-column prop="coverImage" label="封面图片" width="250" />-->
      <el-table-column fixed="right" label="Operations" width="150">
        <template #default="data">
          <el-button size="small" @click="lookButton(data.row.userId)">查看</el-button>
          <el-button size="small" @click="delectButton(data.row.userId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
  <div class="demo-pagination-block">
    <div class="demonstration"></div>
    <h4>总页数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </h4>
    <el-pagination
        v-model:current-page=current
        :page-size=size
        :small="small"
        :disabled="disabled"
        :background="background"
        layout="total, prev, pager, next"
        :total=total
        @size-change="getSizeChange"
        @current-change="getCurrentPage"
    />
  </div>
</template>

<script>
import request from "@/utils/request";
import router from "@/router";

export default {
  name: "AdminManagePersonTable.vue",
  components:{

  },

  data(){
    return{
      tableData:[
        {
          id:'',
          userId:'',
          email:'',
          mobilePhoneNumber:'',
          nickname:'',
          ip:'',
          school:'',
          major:'',

        }
      ],

      current:1,
      total: 9,
      size: 9,
      pages: 10,
    }
  },

  created() {
    this.load()
  },

  methods:{
    load() {
      request.get("/user/getAllUser/"+this.current).then(res => {
        console.log(res.data)
        if (res.data == 500) {
          alert("返回错误,返回文章检索页面!")
          router.push("/ArticleSearchView")
        } else {
          if (res.data.records!=null){
            this.tableData=res.data.records
            this.size=res.data.size
            this.pages=res.data.pages
          }
          else {
            this.tableData=res.data
          }
        }
      })
    },

    getCurrentPage(current){
      request.get("/user/getAllUser/"+current).then(res => {
        console.log(res.data)
        if (res.data.records!=null){
          this.tableData=res.data.records
          this.size=res.data.size
          this.pages=res.data.pages
        }
        else {
          this.tableData=res.data
        }
      })
    },

    lookButton(){

    },
    delectButton(){

    },
  }
}
</script>

<style scoped>

</style>